<div id="contract_view" style="min-width:700px;width:1000px;overflow:hidden;height: auto">
    <div class="titleLogin" style="padding: 5px;margin-bottom: 5px;">
        Xem chi tiết "<?php echo $contract->name ?>"
    </div>
    <table class="EditTable" cellspacing="1" align="center" cellpadding="2" border="0"
           style="table-layout:fixed;width:470px;">
        <tbody>
        <tr>
        </tr>
        <tr>
            <td width="40%"><span>Ngày hợp đồng:</span></td>
            <td><b><?php echo $contract->date ?></b></td>
        </tr>
        <tr>
            <td><span>Số hợp đồng:</span></td>
            <td><b><?php echo $contract->contract ?></b></td>
        </tr>
        <tr>
            <td><span>Người đại diện:</span></td>
            <td><b><?php echo $contract->director ?></b></td>
        </tr>
        <tr>
            <td><span>Chức vụ:</span></td>
            <td><b><?php echo $contract->position ?></b></td>
        </tr>
        <tr>
            <td><span>Ngày biên bản:</span></td>
            <td>
                <div class="input-group" style="width:150px">
                    <input class="form-control" id="datebb" value="<?php echo $contract->datebb ?>" name="datebb"
                           data-date-format="dd/mm/yyyy">
																		<span class="input-group-addon">
																			<i class="icon-calendar bigger-110"></i>
																		</span>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <?php if (!empty($contract->marketing)){ ?>
                <span>NVKD: <b><?php echo $contract->marketing; ?></b> -
                    <?php } ?>
                    Người nhập cuối: <b><?php echo $contract->userlog ?></b> - Ngày nhập cuối: <b><?php echo $contract->datelog ?></b></span>
            </td>
        </tr>
        <?php if (!empty($contract->note)) { ?>
            <tr>
                <td colspan="2">Ghi chú: <b><?php echo $contract->note ?></b></td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
    <br>
    <table border="0" class="table table-striped table-bordered table-hover dataTable">
        <thead>
        <tr>
        </tr>
        <tr>
            <td align="center">STT</td>
            <td align="center">Tên sản phẩm, hàng hóa</td>
            <td align="center">Quy cách</td>
            <td align="center">Đơn vị tính</td>
            <td align="center">Số lượng</td>
            <td align="center">Đơn giá</td>
            <td align="center">Thành tiền</td>
        </tr>
        </thead>
        <tbody valign="middle">
        <tr>
        </tr>
        <?php
        if ($contract['product']) {
            foreach ($contract['product'] as $product) {
                ?>
                <tr>
                    <td align="center"><b><?php echo $product->order ?></b></td>
                    <td align="left">
                        <b><?php echo $product->product_name ?> <?php echo $product->product_page ?> liên</b><br>
                        + Mẫu số: <b><?php echo $product->form ?></b><br>
                        + Ký hiệu: <b><?php echo $product->serial ?></b><br>
                        + Số: <b><?php echo $product->quantity_t ?> - <?php echo $product->quantity_d ?></b>
                    </td>
                    <td align="left">
                        - Số màu: <b><?php echo $product->color ?> màu</b><br>
                        - Ruột: <b><?php echo $product->bowel ?></b><br>
                        - Kích thước: <b><?php echo $product->size ?></b><br>
                        - Chống ký: <b><?php echo $product->signed ?></b>
                    </td>
                    <td align="center"><b><?php echo $product->unit ?></b></td>
                    <td align="center"><b><?php echo $product->quantity ?></b></td>
                    <td align="right"><b><?php echo $product->price ?></b></td>
                    <td align="right"><b><?php echo $product->total ?></b></td>
                </tr>
            <?php }
        } ?>
        <tr>
            <td colspan="6" align="right">Cộng tiền hàng:</td>
            <td align="right"><b><?php echo $contract->sub_total; ?></b></td>
        </tr>
        <tr>
            <td colspan="6" align="right">Thuế GTGT 10%:</td>
            <td align="right"><b><?php echo $contract->vat_total; ?></b></td>
        </tr>
        <tr>
            <td colspan="6" align="right">Tổng tiền thanh toán:</td>
            <td align="right"><b><?php echo $contract->grand_total; ?></b></td>
        </tr>
        <tr>
            <td align="center" colspan="7">Số tiền viết bằng chữ:
                <b><?php echo Helper::number($contract->grand_total); ?> Đồng!</b></td>
        </tr>
        <tr>
        </tr>
        <tr>
            <td align="center" colspan="7">
                <input class="btn btn-sm btn-primary" id="btnhopdong" type="button" name="hopdong" value="Hợp Đồng"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'hopdong', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="thanhly" value="Thanh Lý"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'thanhly', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="bangiao" value="Bàn Giao"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'bangiao', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="kiemtra" value="Kiểm Tra"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'kiemtra', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="niemphong" value="Niêm Phong"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'niemphong', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="huy" value="Hủy"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'huy', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="phieuthu" value="Phiếu Thu"
                       onClick="window.open('<?php echo Yii::app()->createUrl('contract/print', array('type' => 'phieuthu', 'id' => $contract->contract_id, 'file' => 'pdf')) ?>')">&nbsp;&nbsp;
                <input class="btn btn-sm btn-primary" type="button" name="hoadon" value="Hóa Đơn"
                       onClick="window.open('<?php echo Yii::app()->createUrl('invoice/create', array('type' => 'hopdong', 'id' => $contract->contract_id)) ?>')">&nbsp;&nbsp;
            </td>
        </tr>
        </tbody>
    </table>
</div>
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/bootstrap-datepicker.min.js"></script>
<script>
    var datebb = $('#datebb').datepicker({
        'format': 'dd/mm/yyyy',
        'autoclose': true,
        'orientation': "top left",
        'language': "vi"
    });
    datebb.on('changeDate', function (ev) {
        $.ajax({
            url: '<?php echo Yii::app()->createUrl('contract/datebb',array('id'=>$contract->contract_id))?>',
            data: 'value=' + ev.date.valueOf(),
            type: "POST"
        });
    });
    datebb.next().on('click', function () {
        $(this).prev().focus();
    });
</script>